﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Share;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System.IO;

namespace NewtonJsonUsage
{
    public static class ToFile
    {
        public static void Demo()
        {
            Product product = new Product();
            product.ExpiryDate = new DateTime(2008, 12, 28);

            JsonSerializer serializer = new JsonSerializer();
            //serializer.Converters.Add(new JavaScriptDateTimeConverter());
            //serializer.NullValueHandling = NullValueHandling.Ignore;

            using (StreamWriter sw = new StreamWriter(AppDomain.CurrentDomain.BaseDirectory + @"\json.txt"))
            {
                using (JsonWriter writer = new JsonTextWriter(sw))
                {
                    serializer.Serialize(writer, product);
                }
            }
        }
    }
}
